package com.taojie.graduation.controller;

import com.taojie.graduation.domain.Car;
import com.taojie.graduation.service.api.CarService;
import com.taojie.graduation.utils.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @ClassName CarController
 * @Description TODO
 * @Author Chole
 * @Date 2020/4/20 9:40
 */
@RestController
@CrossOrigin
@Api(tags = {"购物车接口"})
@RequestMapping("car")
public class CarController {

    @Resource
    CarService carService;

    @ApiOperation("分页查询")
    @GetMapping("{page}/{size}")
    public Result page(@PathVariable("page") int page, @PathVariable("size") int size, @RequestParam(value = "query", required = false) String query){
        return carService.findCarPage(page, size, query);
    }

    @ApiOperation("根据id修改购物车")
    @PutMapping("{id}")
    public Result updateById(@PathVariable("id") Integer id,@RequestBody Car car){
        car.setId(id);
        return carService.updateById(car);
    }

    @ApiOperation("根据id查询购物车")
    @GetMapping("{id}")
    public Result findById(@PathVariable("id") Integer id){
        return carService.findCarById(id);
    }

}
